'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFSkCtrl
 * @description
 * # FinanceFSkCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFSkCtrl', function ($scope, $rootScope, openApi, $http, Util, $location, $routeParams, FormSubmit) {
        var selectData, params;
        // --------------------------------------
        // var payTypeList = [
        //     {
        //         key: "往来",
        //         value: "往来"
        //     }, {
        //         key: "费用",
        //         value: "费用"
        //     }];

        $scope.sheetObj = {};
        // 底部关联模块类型选框添加
        var relModuleObj = {},
            selectData;
        relModuleObj.sheettitle = "关联模块";
        relModuleObj.callback = function (item) {
            if (item.selectTabContent == "无") {
                $scope.param.relatedModuleName = "无";
                $scope.param.relatedModule = "";
                $scope.param.moduleNo = "";
                return;
            }
            $scope.param.relatedModule = item.selectTab;
            $scope.param.relatedModuleName = item.selectTabContent;
            $scope.param.moduleNo = ""
        }
        $scope.sheetObj.relModuleObj = relModuleObj;
        $scope.showrelModule = function () {
            Util.getModuleRel(Util.OTH_MODULE, function (data) {
                $scope.sheetObj.relModuleObj.tabList = data.data
                $scope.showSheet("relModuleObj")
            })

        };

        $scope.showSheet = function (type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };
        //------------------------------关联模块
        // 底部款项类型选框添加
        var payTypeObj = {};
        payTypeObj.sheettitle = "收款类型";
        // payTypeObj.tabList = payTypeList;
        payTypeObj.callback = function (item) {
            $scope.param.payType = item.selectTab
            $scope.param.typeContent = item.selectTabContent
        }
        $scope.sheetObj.payTypeObj = payTypeObj;
        $scope.getpaytype = function () {
            var param = {};
            param.type = "收款类型";
            Util.getKeyValue(param, function (data) {
                payTypeObj.tabList = data.data
                // $scope.payTypeList = data.data
                $scope.showSheet('payTypeObj');
            })
        }
        $scope.chooseinfo = function () {
            // $routeParams.id通过id确定唯一回显id
            if (!$scope.param.relatedModule) {
                return
            }
            Util.savaParamForReview($scope.param, $routeParams.id);
            // 里面包含了title
            var relModuleObj = {
                name: "FinanceFSkCtrl",
                selectTab: $scope.param.relatedModule,
                selectTabContent: $scope.param.relatedModuleName
            };
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")

        };
        $scope.choosePeople = function () {
            relModuleObj = {
                name: "FinanceFSkCtrl",
                selectTab: "select_user"
            };
            // 清掉关联的编号
            Util.savaParamForReview($scope.param, $routeParams.id);
            Util.savaDataforsearch(relModuleObj);

            $location.path("finance/choosepeople")
        };

        // 提交申请
        $scope.submit = function () {
            if (!$scope.param.payPerson) {
                Util.Toast("请选择交款人");
                return;
            }
            if (!$scope.param.payType) {
                Util.Toast("请选择收款类型");
                return;
            }
            if (!$scope.param.amount) {
                Util.Toast("请输入收款金额");
                return;
            }
            if (!$scope.param.remark) {
                Util.Toast("请填写收款事由");
                return;
            }
            if ($scope.param.relatedModuleName && $scope.param.relatedModuleName !== "无") {
                if (!$scope.param.moduleNo) {
                    Util.Toast("请选择模块编号");
                    return;
                }
            }
            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.otherMoney
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param;
            // 如果是修改页面的话则提交的地址不一样，参数一样
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显

            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.otherMoney
            }
            new FormSubmit(options);
        };
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function (data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function (data) {
                $scope.logData = data;
            });

        };
        // 初始化
        init();
    });
